<?php
/**
* 로그인 실행로직
* /admin/logic/help/login.php
* 2008-05-06
* Hamhaja <hamhaja@nextez.co.kr>
*/
$App->class_require('Table.Member');
$Member = new Member(&$Db);

if ($g_subjob == 'form')
{
	if ($User->is_admin())
	{
		echo $Html->redirect($App->_url_admin . "/index.php");
		exit;
	}
}
else if ($g_subjob == 'login')
{
	if (!$App->check_method(POST)) g_fail(NO_PERMIT_METHOD);

	if ($Member->check_admin($_POST['id'], $_POST['pw']))
	{
		$Member->connect($_POST['id']);

		if ($User->register($_POST['id']))
		{
			//$App->reload();
			echo "<script type='text/javascript'>document.location.href='/ezadm/index.php';</script>";

		}
		else $Error->fail(LOGIN_FAIL);
	}
	else $Error->fail(LOGIN_FAIL, '관리자 아이디/비밀번호가 일치하지 않습니다.');
}
else if ($g_subjob == 'init')
{
	if (!$Member->check_id('admin'))
	{
		$cols = array(
			'mb_id' => 'admin',
			'mb_name' => '최고관리자',
			'mb_nickname' => '넥스트이지',
			'mb_level' => 1,
			'mb_pw' => 'nextez307',
		);
		if ($Member->insert($cols, array('mb_lip', 'mb_ctime')))
		{
			$Success->success(INIT_SUCCESS, '', false);
			$next_url = $App->_url_admin . "/index.php?g_job=help_login";
			$Script->location($next_url, 'parent');
		}
		else $Error->fail(INIT_FAIL);
	}
	else $Error->fail(INIT_FAIL, "이미 초기화 되었습니다.");
}
?>
